home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / cheetah.zip / CPUTZP.C < prev    next >
C/C++ Source or Header  |  1992-08-18  |  4KB  |  105 lines

  1. /* cputzp.c  -  Decoding image in ZPacked format to VRAM, CHAINED mode.
  2.  *
  3.  * Description:
  4.  *   Format ZPacked is quiet the same as Z4Planes but without breaking
  5.  *   into planes.
  6.  *   Uses the coding method, described in mputz4p.c
  7.  * See Also:
  8.  *      mputz4p.c, uputz4p.c
  9.  * Functions:
  10.  *      CputZPacked().
  11.  * Portability: BORLANDC
  12.  *                                      (c) erdy 1992
  13.  * $Header: $
  14.  */
  15. #pragma inline
  16. #include "far.h"
  17. #include "vgaprefx.h"
  18. #include "vgadrv.h"
  19. #include "screen.h"
  20.  
  21.  
  22. void CputZPacked(char far *image, unsigned x, unsigned y, int rows)
  23.         /* in case of ZC_PREPARED x is unused, y contains VRAM offset.
  24.          */
  25. {
  26.         _ES = Scdraw_seg;
  27.  
  28.     asm push ds;
  29.     asm lds si, image;
  30.     asm cld;
  31. #       ifdef ZC_PREPARED
  32.                 asm mov di, y;
  33. #       else  ZC_PREPARED
  34.                 _DI = VIDEO_CADDRESS(x, y);
  35. #       endif ZC_PREPARED
  36.  
  37.          /* CX contains row counter.
  38.          */
  39.         asm mov cx, rows;
  40.         asm push bp;
  41.         asm mov dx, BPERROW_CHAINED;
  42.         asm xor ah, ah;
  43. RowLoop:
  44.                 /*
  45.                  * Scanlines loop. CX contains nrows.
  46.                  *
  47.                  * Sequence of the alhorithm follows the most frequent image
  48.                  * sequence: <skip>, <literal>, <skip/eol>.
  49.                  * Thus, at least 3 jumps per line are saved.
  50.                  *
  51.                  * Scratch registers:
  52.                  *      bx - saving the ram index (di)
  53.                  *      bp - saving the loop counter (cx)
  54.                  */
  55.                 asm mov bx, di;                 /* Save ram index */
  56.                 asm mov bp, cx;                 /* Save loop counter */
  57.                 asm xor ch, ch;                 /* Zero high byte, ch always zero */
  58.                 /* Loop until EOL */
  59. LineLoop:
  60.                         asm lodsb;              /* Get next image byte */
  61.                         asm or al, al;          /* Query flags */
  62.                         asm jg short Literal;   /* al > 0, so literally */
  63.                         asm je short String;    /* al == 0, so string */
  64.  
  65. Skip:                                           /* Otherwise skipping */
  66.                         asm neg al;             /* Invert counter */
  67.                         asm jo Eol;             /* Overflow, i.e. neg 128 */
  68.                                                 /* asm mov cl, al; /* Move counter */
  69.                         asm add di, ax;         /* Advance the index. ah is 0! */
  70.  
  71.                         asm lodsb;              /* Get next image byte */
  72.                         asm or al, al;          /* Query flags */
  73.                         asm jl short Skip;      /* al < 0, so skipping */
  74.                         asm je short String;    /* al == 0, so string */
  75.  
  76. Literal:                                        /* Otherwise literal */
  77.                         asm mov cl, al;         /* Move counter */
  78.                         asm rep movsb;          /* Copy cx bytes */
  79.                         asm lodsb;              /* Get next image byte */
  80.                         asm or al, al;          /* Query flags */
  81.                         asm jl short Skip;      /* al < 0, so skipping */
  82.                         asm jg short Literal;   /* al > 0, so literally */
  83.  
  84. String:                                         /* Otherwise string */
  85.                         asm lodsb;              /* Get counter byte */
  86.             asm mov cl, al;        /* Put counter to cl */
  87.                         asm lodsb;              /* Get color byte into al */
  88.                         asm rep stosb;          /* Store cx bytes of al */
  89.                         asm lodsb;              /* Get next image byte */
  90.                         asm or al, al;          /* Query flags */
  91.                         asm jg short Literal;   /* al > 0, so literally */
  92.                         asm jl short Skip;      /* al < 0, so skipping */
  93.                         asm jmp short String;   /* Otherwise, string once more */
  94. Eol:
  95.         /*--same--as--mputz4p.c---*/
  96.         asm mov di, bx;                 /* Restore ram index */
  97.                 asm add di, dx;                 /* Add BPERROW_CHAINED, advance ram index to next row */
  98.  
  99.         asm mov cx, bp;                 /* Restore row counter */
  100.         asm loop RowLoop;
  101.  
  102.         asm pop bp;
  103.     asm pop ds;
  104.     return;
  105. }